package com.niit.dao.impl;

import java.util.List;

import com.niit.bean.Job;
import com.niit.dao.JobDao;
import com.niit.utils.DbUtil;

public class JobDaoImpl implements JobDao {

	private DbUtil util=new DbUtil();
	@Override
	public int add(Job t) {
		String sql="insert into tb_job(title,enterprise,education,expirence,district,descri,require) values(?,?,?,?,?,?,?)";
		int a=util.update(sql, t.getTitle(),t.getEnterprise(),t.getEducation(),t.getExpirence(),t.getDistrict(),t.getDescri(),t.getRequire());
		return a;
	}

	@Override
	public int delete(Job t) {
		String sql="delete from tb_job where id=? ";
		int a=util.update(sql, t.getId());
		return a;
	}

	@Override
	public int update(Job t) {
		String sql="update tb_job set title=?,enterprise=?,time=?,education=?,expirence=?,district=?,descri=?,require=? ";
		int a=util.update(sql, t.getTitle(),t.getEnterprise(),t.getTime(),t.getEducation(),t.getExpirence(),t.getDistrict(),t.getDescri(),t.getRequire());
		return a;
	}

	@Override
	public List<Job> findAll(int start, int end) {
		String sql="select * from(select rownum r,tb_job.* from tb_job) a where a.r>? and a.r<=? ";
		List<Job> list=util.select(sql, Job.class, start,end);
		return list;
	}

	@Override
	public int findTotal() {
		String sql="select count(*) from tb_job ";
		int count=util.selectCount(sql);
		return count;
	}

	@Override
	public Job findById(String id) {
		String sql = "select * from tb_job where id = ?";
		List<Job> list = util.select(sql, Job.class, id);
		int count=list.size();
		if(count==0){
			return null;
		}else{
			Job job = list.get(0);
			return job;
		}
	}

	@Override
	public List <Job> findByEdu(String education, int start, int end) {
		String sql="select * from(select rownum r,tb_job.* from tb_job where education=?) a where a.r>? and a.r<=? ";
		List<Job> list=util.select(sql, Job.class, education, start, end);
		return list;
		
	}

	@Override
	public List <Job> findByExp(String expirence, int start, int end) {
		String sql="select * from(select rownum r,tb_job.* from tb_job where expirence=?) a where a.r>? and a.r<=? ";
		List<Job> list=util.select(sql, Job.class, expirence, start, end);
		return list;
	}

}
